package org.huamoxi.utils;

import cn.hutool.core.util.ArrayUtil;

import javax.servlet.http.HttpServletRequest;

import static cn.hutool.extra.servlet.ServletUtil.getClientIPByHeader;

public class ServletUtils {
    public static String doDiscernRequest(HttpServletRequest request) {
        String userAgent = request.getHeader("user-agent");
        String requestDevice = DiscernRequestUtils.getRequestDevice(userAgent);
        return requestDevice;
    }

    public static String getClientIP(HttpServletRequest request, String... otherHeaderNames) {
        String[] headers = { "X-Forwarded-For", "X-Real-IP", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR" };
        if (ArrayUtil.isNotEmpty(otherHeaderNames)) {
            headers = ArrayUtil.addAll(headers, otherHeaderNames);
        }

        return getClientIPByHeader(request, headers);
    }
}
